package com.dengbw.systemtransfer.service;

import com.dengbw.systemtransfer.annotations.TimeSpeaker;
import com.dengbw.systemtransfer.mapper.SysCorpVillageMapper;
import com.dengbw.systemtransfer.model.db.SysCorpVillage;
import com.dengbw.systemtransfer.model.request.CunInfo;
import com.dengbw.systemtransfer.model.request.ZhenTransfer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author dengbw
 * @date 2021/11/11 2:37 下午
 */
@Service
public class SysCorpVillageService {

    AdminAreaService adminAreaService;
    SysCorpVillageMapper sysCorpVillageMapper;

    @Autowired
    public SysCorpVillageService(AdminAreaService adminAreaService, SysCorpVillageMapper sysCorpVillageMapper) {
        this.adminAreaService = adminAreaService;
        this.sysCorpVillageMapper = sysCorpVillageMapper;
    }

    @Transactional(rollbackFor = Exception.class)
    public void saveSysCorpVillage(ZhenTransfer zhenTransfer, CunInfo cunInfo) {
        String areaId = adminAreaService.getAreaId(zhenTransfer.getShi(), zhenTransfer.getQu(), zhenTransfer.getZhen(), cunInfo.getCunName());
        SysCorpVillage village = new SysCorpVillage();
        village.setTenantId(zhenTransfer.getZhenCorpId());
        village.setSubTenantId(cunInfo.getSubIdInZhen());
        village.setName(cunInfo.getCunName());
        village.setNeedSync(1);
        village.setLtFlag(0);
        village.setGbFlag(0);
        village.setAreaId(areaId);
        village.setHasProblem(null);
        sysCorpVillageMapper.insert(village);
    }
}
